<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="../css/base.css">
    <link href="../css/purchase.2012.css?v=201410141639" rel="stylesheet" type="text/css">
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    <title>我的购物车 - shop商城</title>
    <script>
        var pageConfig = {};
    </script>
</head>
<body>
<div id="shortcut-2013">
    <div class="w">
        <ul class="fl lh">
            <li class="fore1 ld" clstag="homepage|keycount|home2013|01a"><b></b><a href="javascript:addToFavorite()"
                                                                                   rel="nofollow">收藏shop</a></li>
        </ul>
        <ul class="fr lh">
            <li class="fore1" id="loginbar" clstag="homepage|keycount|home2013|01b">您好！欢迎来到shop！<a
                    href="javascript:login()">[登录]</a>&nbsp;<a href="javascript:regist()">[免费注册]</a></li>
            <li class="fore2 ld" clstag="homepage|keycount|home2013|01c">
                <s></s>
                <a href="http://jd2008.jd.com/JdHome/OrderList.aspx" rel="nofollow">我的订单</a>
            </li>
            <li class="fore2-1 ld" id="jd-vip">
                <s></s>
                <a target="_blank" rel="nofollow" href="http://vip.jd.com">会员俱乐部</a>
            </li>
            <li class="fore3 ld menu" id="app-jd" data-widget="dropdown" clstag="homepage|keycount|home2013|01d">
                <s></s><i></i><span class="outline"></span><span class="blank"></span>
                <a href="http://app.jd.com/" target="_blank">手机shop</a><b></b>
            </li>
            <li class="fore4 ld menu" id="biz-service" data-widget="dropdown" clstag="homepage|keycount|home2013|01e">
                <s></s>
                <span class="outline"></span>
                <span class="blank"></span>
                客户服务
                <b></b>
                <div class="dd">
                    <div><a href="http://help.jd.com/index.html" target="_blank">帮助中心</a></div>
                    <div><a href="http://myjd.jd.com/repair/orderlist.action" target="_blank" rel="nofollow">售后服务</a>
                    </div>
                    <div><a href="http://chat.jd.com/jdchat/custom.action" target="_blank" rel="nofollow">在线客服</a></div>
                    <div><a href="http://myjd.jd.com/opinion/list.action" target="_blank" rel="nofollow">投诉中心</a></div>
                    <div><a href="http://www.jd.com/contact/service.html" target="_blank">客服邮箱</a></div>
                </div>
            </li>
            <li class="fore5 ld menu" id="site-nav" data-widget="dropdown" clstag="homepage|keycount|home2013|01f">
                <s></s>
                <span class="outline"></span>
                <span class="blank"></span>
                网站导航
                <b></b>
                <div class="dd lh">
                    <dl class="item fore1">
                        <dt>特色栏目</dt>
                        <dd>
                            <div><a target="_blank" href="http://mobile.jd.com/index.do">shop通信</a></div>
                            <div><a target="_blank" href="http://jdstar.jd.com/">校园之星</a></div>
                            <div><a target="_blank" href="http://my.jd.com/personal/guess.html">为我推荐</a></div>
                            <div><a target="_blank" href="http://shipingou.jd.com/">视频购物</a></div>
                            <div><a target="_blank" href="http://club.jd.com/">shop社区</a></div>
                            <div><a target="_blank" href="http://read.jd.com/">在线读书</a></div>
                            <div><a target="_blank" href="http://diy.jd.com/">装机大师</a></div>
                            <div><a target="_blank" href="http://giftcard.jd.com/market/index.action">shopE卡</a></div>
                            <div><a target="_blank" href="http://channel.jd.com/jiazhuang.html">家装城</a></div>
                            <div><a target="_blank" href="http://dapeigou.jd.com/">搭配购</a></div>
                            <div><a target="_blank" href="http://xihuan.jd.com/">我喜欢</a></div>
                        </dd>
                    </dl>
                    <dl class="item fore2">
                        <dt>企业服务</dt>
                        <dd>
                            <div><a target="_blank" href="http://giftcard.jd.com/company/index">企业客户</a></div>
                            <div><a target="_blank" href="http://sale.jd.com/p10997.html">办公直通车</a></div>
                        </dd>
                    </dl>
                    <dl class="item fore3">
                        <dt>旗下网站</dt>
                        <dd>
                            <div><a target="_blank" href="http://en.jd.com/">English Site</a></div>
                        </dd>
                    </dl>
                </div>
            </li>
        </ul>
        <span class="clr"></span>
    </div>
</div>

<div class="w w1 header clearfix">
    <div id="logo"><a href="/"><img clstag="clickcart|keycount|xincart|logo" src="../images/taotao-logo.gif"
                                    title="返回shop商城首页" alt="返回shop商城首页"></a></div>
    <div class="language"><a href="javascript:void(0);" onclick="toEnCart()"></a></div>
    <div class="progress clearfix">
        <ul class="progress-1">
            <li class="step-1"><b></b>1.我的购物车</li>
            <li class="step-2"><b></b>2.填写核对订单信息</li>
            <li class="step-3">3.成功提交订单</li>
        </ul>
    </div>
</div>
<div class="w cart">
    <div class="cart-hd group">
        <h2>我的购物车</h2>
    </div>
    <div id="show">

        <div class="cart-frame">
            <div class="tl"></div>
            <div class="tr"></div>
        </div>
        <div class="cart-inner">
            <div class="cart-thead clearfix">
                <div class="column t-checkbox form"><input data-cart="toggle-cb" name="toggle-checkboxes"
                                                           id="toggle-checkboxes_up" type="checkbox" checked=""
                                                           value=""><label for="toggle-checkboxes_up">全选</label></div>
                <div class="column t-goods">商品</div>
                <div class="column t-price">shop价</div>
                <div class="column t-promotion">优惠</div>
                <div class="column t-inventory">库存</div>
                <div class="column t-quantity">数量</div>
                <div class="column t-action">操作</div>
            </div>
            <div id="product-list" class="cart-tbody">

            </div><!-- product-list结束 -->
            <div class="cart-toolbar clearfix">
                <div class="total fr">
                    <p><span class="totalSkuPrice">¥${totalPrice / 100}</span>总计：</p>
                    <p><span id="totalRePrice">- ¥0.00</span>优惠：</p>
                </div>
                <div class="amout fr"><span id="selectedCount">1</span> 件商品</div>
            </div>
            <div class="ui-ceilinglamp-1" style="width: 988px; height: 49px;">
                <div class="cart-dibu ui-ceilinglamp-current" style="width: 988px; height: 49px;">
                    <div class="control fdibu fdibucurrent">
              <span class="column t-checkbox form">
                  <input data-cart="toggle-cb" name="toggle-checkboxes" id="toggle-checkboxes_down" type="checkbox"
                         checked="" value="" class="jdcheckbox">
                  <label for="toggle-checkboxes_down">
                          全选
                  </label>
              </span>
                        <span class="delete">
                  <b>
                  </b>
                  <a href="javascript:void(0);" clstag="clickcart|keycount|xincart|clearcartlink" id="remove-batch"
                     onclick="deleList()">
                          删除选中的商品
                  </a>
              </span>
                        <span class="shopping">
                  <b>
                  </b>
                  <a href="/" target="_blank" clstag="clickcart|keycount|xincart|coudanlink" id="continue">继续购物</a>
              </span>
                    </div>
                    <div class="cart-total-2014">
                        <div class="cart-button">
                  <span class="check-comm-btns" id="checkout-jd">
                      <a class="checkout" href="javascript:void(0);" onclick="gotoOrderCart()"
                         clstag="clickcart|keycount|xincart|gotoOrderInfo" id="toSettlement">去结算<b></b></a>
                  </span>
                            <span class="combine-btns" style="display:none">
                        <span class="fore1" style="display: none;">
                          <a href="" class="combine-btn">不支持合并付款</a>
                      </span>
                      <span class="fore2 hide" style="display: inline;">
                          <a href="javascript:goToOverseaOrder();" class="checkout-jdInt">去shop国际结算<b></b></a>
                          <a href="javascript:goToOrder();" class="checkout-jd">去shop结算<b></b></a>
                      </span>
                  </span>
                        </div>
                        <div class="total fr">
                            总计（不含运费）：
                            <span id="total" class="totalSkuPrice">¥ 0</span>
                        </div>
                    </div>
                </div>
            </div>
        </div><!-- cart-inner结束 -->
    </div>
</div>
<!--推荐位html修改处-->

<!-- 购物车相关业务 -->
<!--<script type="text/javascript" src="../js/cart.js"></script>-->
<!--<script type="text/javascript" src="../js/jquery.price_format.2.0.min.js"></script>-->

</body>
<script>

    var baseURL = 'http://localhost:8005/cart/';
    var data = {
        co: 'userID:7'
    };

    $.ajax({
        url: `${baseURL}findCartList`,
        type: 'post',
        data: data,
        dataType: 'json'
        // contentType: 'application/json'
    }).done(function (result) {
        for (var i = 0; i < result.length; i++) {

            var newProduct = $("<div id='product_11345721' data-bind='rowid:1' class='item item_selected'></div>");
            $("#product-list").append(newProduct);

            var item_from_clearfix = $("<div class='item_form clearfix'></div>");
            newProduct.append(item_from_clearfix);

            var newChecked = $("<div class='cell p-checkbox'><input data-bind='cbid:2' class='checkbox' type=\"checkbox\" name='checkItem' checked='' value='" + result[i].entity.id + "'></div>");
            item_from_clearfix.append(newChecked);
            // 商品 div cell p-goods
            var newCell_p_goods = $("<div class='cell p-goods'>\n" +
                "                            <div class='p-img'>\n" +
                "                                <a href='/item/" + result[i].entity.id + ".html' target='_blank'>\n" +
                "                                    <img clstag='clickcart|keycount|xincart|p-imglistcart' src='" + result[i].entity.image + "' alt='" + result[i].entity.title + "' width='52'\n" +
                "                                         height=\"52\"></a>\n" +
                "                            </div>\n" +
                "                            <div class='p-name'>" +
                "                                <a href='/item/" + result[i].entity.id + ".html' clstag=\"clickcart|keycount|xincart|productnamelink\"\n" +
                "                                   target=\"_blank\">" + result[i].entity.title + "</a>\n" +
                "                                <span class=\"promise411 promise411_11345721\" id=\"promise411_11345721\"></span>\n" +
                "                            </div>\n" +
                "                        </div>");
            item_from_clearfix.append(newCell_p_goods);

            var newCell_p_price = $("<div class='cell p-price'><span class='price'>￥" + result[i].entity.price + "</span></div>");
            item_from_clearfix.append(newCell_p_price);

            var newCell_p_cutprice = $("<div class='cell p-price'><span class='price'>暂无优惠</span></div>\n");
            item_from_clearfix.append(newCell_p_cutprice);

            var newCell_p_inventory = $("<div class='cell p-inventory stock-11345721'>" + result[i].isExists + "</div>");
            item_from_clearfix.append(newCell_p_inventory);

            var newCell_p_quantity = $("<div class='cell p-quantity' for-stock='for-stock-11345721'></div>");
            item_from_clearfix.append(newCell_p_quantity);

            newCell_p_quantity.append(" <div class='quantity-form' data-bind=''>\n" +
                "                                <a href='javascript:void(0);'  class='decrement'\n" +
                "                                   clstag='clickcart|keycount|xincart|diminish1' id='decrement'>-</a>\n" +
                "                                <input type='text' class='quantity-text'  itemPrice=" + result[i].entity.price + " itemId=" + result[i].entity.id + "  value=" + result[i].count + "\n" +
                "                                        id='changeQuantity-11345721-1-1-0'>\n" +
                "                                <a href='javascript:void(0);' class='increment' clstag='clickcart|keycount|xincart|add1'\n" +
                "                                   id='increment'>+</a>\n" +
                "                            </div>");

            var newCell_p_remove = $("<div class='cell p-remove'><a id='remove-11345721-1' data-more='removed-87.20-1'\n" +
                "                                                      clstag='clickcart|keycount|xincart|btndel318558'\n" +
                "                                                      class='cart-remove' href='javascript:void(0);' onclick='dele(" + result[i].entity.id + ")'>删除</a>\n" +
                "                        </div>");
            item_from_clearfix.append(newCell_p_remove);
        }

        var total = 0;
        var selectedCount = 0;
        for (let i = 0; i < result.length; i++) {

            selectedCount += result[i].count;

            total += result[i].count * result[i].entity.price;
        }

        $("#selectedCount").text(selectedCount);
        $(".totalSkuPrice").text(total);


    });

    function dele(itemId) {

        $.ajax({
            url: `${baseURL}delete/` + itemId,
            type: 'post',
            success: function (bln) {
                window.location.href = "cart.html";
            }
        })
    }

    function gotoOrderCart() {

        let arr = Array();
        $("#product-list").find("input[type='checkbox']").each(function () {

            if ($(this).prop("checked")) {
                arr.push($(this).val());
            }
        });
        let total = parseInt($("#total").text());
        $.ajax({
            url: 'http://localhost:8005/orderCart/sendItems',
            type: "post",
            contentType: 'application/json',
            data: JSON.stringify({total: total,array: arr})

        }).done(function (result) {
            if (result === 1) {
                window.location.href="order-cart.html";
            }else {
                alert("提交失败");
            }

        });
    }

    //点上面的全选
    $("#toggle-checkboxes_up").click(function () {
        if ($(this).prop("checked")) {
            $("#product-list").find("input[type='checkbox']").prop("checked", true);
            $("#toggle-checkboxes_down").prop("checked", true);
        } else {
            $("#product-list").find("input[type='checkbox']").prop("checked", false);
            $("#toggle-checkboxes_down").prop("checked", false);
        }

        tranfrom();
    });
    //点下面的全选
    $("#toggle-checkboxes_down").click(function () {
        if ($(this).prop("checked")) {
            $("#product-list").find("input[type='checkbox']").prop("checked", true);
            $("#toggle-checkboxes_up").prop("checked", true);
        } else {
            $("#product-list").find("input[type='checkbox']").prop("checked", false);
            $("#toggle-checkboxes_up").prop("checked", false);
        }
        tranfrom();
    });
    //点单个的checkbox
    $("#product-list").on("click", "input[type='checkbox']", function () {

        if ($(this).prop("checked")) {
            let all = $("#product-list").find("input[type='checkbox']").length;
            let subtotal = $("#product-list").find("input:checked").length;
            if (all === subtotal){
                $("#toggle-checkboxes_up").prop("checked", true);
                $("#toggle-checkboxes_down").prop("checked", true);
            }
        } else {
            $("#toggle-checkboxes_up").prop("checked", false);
            $("#toggle-checkboxes_down").prop("checked", false);
        }
        tranfrom();
    });

    //减
    $("#product-list").on("click", "a#decrement", function () {

        let id = $(this).parent().find("input").attr("itemid");

        let count = parseInt($(this).parent().find("input").val());
        if (count === 1) {
        } else {
            count -= 1
        }

        $(this).parent().find("input").val(count);

        tranfrom();
        ajax(count, id);
    });

    //加
    $("#product-list").on("click", "a#increment", function () {

        let id = $(this).parent().find("input").attr("itemid");

        let count = parseInt($(this).parent().find("input").val()) + 1;

        $(this).parent().find("input").val(count);
        tranfrom();
        ajax(count, id);
    });

    $("#product-list").on("click", "input#changeQuantity-11345721-1-1-0", function () {

        let id = $(this).parent().find("input").attr("itemid");

        let count = parseInt($(this).parent().find("input").val());

        if (count === 0) {

        } else {
            ajax(count, id);
        }
    });

    function ajax(count, id) {
        $.ajax({
            url: `${baseURL}update`,
            type: 'post',
            data: {count: count, id: id},
            success: function (result) {
                if (result) {
                    window.location.href = "cart.html";
                }
            }
        })
    }

    //计算总计
    function tranfrom() {
        let checked = $("#product-list").find("input:checked");
        let sum = 0;
        let count = 0;

        checked.each(function () {
            let input = $(this).parent().parent().find("#changeQuantity-11345721-1-1-0")

            sum +=  parseInt(input.attr("itemprice")) * parseInt(input.val());
            count += parseInt(input.val()) ;
        });
        $(".totalSkuPrice").text(sum);
        $("#selectedCount").text(count);
    }


</script>
</html>